package com.example.wan_android.viewmodel

import android.content.Intent
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.wan_android.http.bean.FriendItemData
import com.example.wan_android.http.code.FriendRepository
import com.example.wan_android.ui.activity.WebActivity
import kotlinx.coroutines.launch

class FriendWebViewModel : BaseViewModel() {
    private val repository = FriendRepository()
    private val _friendLiveData = MutableLiveData<Result<List<FriendItemData>>>()
    val friendLiveData = _friendLiveData


    init {
        getFriends()
    }

    fun getFriends() {
        viewModelScope.launch {
            _friendLiveData.value = repository.fetchFriends()
        }
    }

    fun openWeb(url: String) {
        startActivity(Intent().apply {
            putExtra(WebViewModel.url, url)
        }, targetClass = WebActivity::class.java)
    }
}